package com.example.denglu.Appframe;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.denglu.DengLu.LengLu;
import com.example.denglu.R;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class UsesFragment extends Fragment implements View.OnClickListener {


    private Button finshfun;
    private ImageView usesimg;
    private TextView usesname;
    private TextView usesxx;
    private TextView usesdk;
    private TextView usesxgmm;
    private TextView usesyjfk;
    private Button usesdlbut;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_uses, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        onclick();

    }


//    private void posttoke() {
//        new Thread(new Runnable() {
//            @Override
//            public void run() {
//
//
//                OkHttpClient client = new OkHttpClient().newBuilder()
//                        .build();
//                MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
//                Request request = new Request.Builder()
//                        .url("http://124.93.196.45:10001/prod-api/api/common/user/getInfo")
//                        .method("GET", null)
//                        .addHeader("Content-Type", "application/x-www-form-urlencoded")
//                        .addHeader("Authorization", toke  )
//                        .build();
//                try {
//                    Response response = client.newCall(request).execute();
//                    client.newCall(request).enqueue(new Callback() {
//                        @Override
//                        public void onFailure(@NonNull Call call, @NonNull IOException e) {
//
//                        }
//                        @Override
//                        public void onResponse(@NonNull Call call, @NonNull Response response) throws IOException {
//                            String string = response.body().string();
//                            try {
//                                JSONObject stringjsonObject = new JSONObject(string);
//
//                                int code = stringjsonObject.getInt("code");
//
//                                if (code == 200) {
//                                    JSONObject userarr = stringjsonObject.getJSONObject("user");
//                                    usescookie.edit().putString("balance",userarr.getString("balance")).commit();
//                                    usescookie.edit().putString("email",userarr.getString("email")).commit();
//                                    usescookie.edit().putString("idCard",userarr.getString("idCard")).commit();
//                                    usescookie.edit().putString("phonenumber",userarr.getString("phonenumber")).commit();
//                                    usescookie.edit().putString("score",userarr.getString("score")).commit();
//                                    usescookie.edit().putString("idCard",userarr.getString("idCard")).commit();
//                                    usescookie.edit().putInt("sex",userarr.getInt("sex")).commit();
//                                    usescookie.edit().putString("userId",userarr.getString("userId")).commit();
//                                    usescookie.edit().putString("nickName",userarr.getString("nickName")).commit();
//
//                                }
//
//                            } catch (JSONException e) {
//                                getActivity().runOnUiThread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        Toast.makeText(getActivity(), "转换失败", Toast.LENGTH_SHORT).show();
//                                    }
//                                });
//                            }
//
//
//                        }
//                    });
//                } catch (IOException e) {
//                    getActivity().runOnUiThread(new Runnable() {
//                        @Override
//                        public void run() {
//                            Toast.makeText(getActivity(), "请求网络服务器失败", Toast.LENGTH_SHORT).show();
//                        }
//                    });
//                }
//            }
//        }).start();
//    }

    private void onclick() {
        usesimg.setOnClickListener(this);
        usesname.setOnClickListener(this);
        usesxx.setOnClickListener(this);
        usesdk.setOnClickListener(this);
        usesxgmm.setOnClickListener(this);
        usesyjfk.setOnClickListener(this);
        usesdlbut.setOnClickListener(this);
    }

    private void initView(View view) {
        usesimg = view.findViewById(R.id.usesimg);
        usesname = view.findViewById(R.id.usesname);
        usesxx = view.findViewById(R.id.usesxx);
        usesdk = view.findViewById(R.id.usesdk);
        usesxgmm = view.findViewById(R.id.usesxgmm);
        usesyjfk = view.findViewById(R.id.usesyjfk);
        usesdlbut = view.findViewById(R.id.usesdlbut);
    }

    @Override
    public void onClick(View v) {
        if (v.getId()==R.id.usesdlbut){
            Intent intent = new Intent(getActivity(), LengLu.class);
            startActivity(intent);
        }
        else if (v.getId()==R.id.usesxx){

        }
        else if (v.getId()==R.id.usesdk){

        }
        else if (v.getId()==R.id.usesxgmm){

        }
        else if (v.getId()==R.id.usesyjfk){

        }
    }
}